<?php
/**
 * Validierungsklasse zur Parametervalidierung
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2013 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 *
 * */


/**
 * $val muss einem Zeitstempel im Format 2010-07-13 entsprechen
 * */
Class Yapary_Parameter_CheckDate Extends Yapary_Exception_Error Implements Yapary_Parameter_ICheck
{
	function __construct ( )
	{

	}


	public function typedef ( $val )
	{
		return (string) $val;
	}


	public function getPattern () {
		return '^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])$';
	}


	public function isValid ( $val )
	{
		if (!isset($val)) {
			$this->addError(Yapary_Exception_Error::E_UNDEFINED);
			return false;
		}
		if (!preg_match('/'.$this->getPattern().'/', $val)) {
			$this->addError(Yapary_Exception_Error::E_WRONG_FORMAT);
			return false;
		}

		return true;
	}

}
